<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./tool.js"></script>
    <title>Document</title>
</head>

<body>

    <script>
        // 统计每个数值下期出现的数值总数并排列，
        function sortMinAndMax(json) {
            let data = {}, t = {};
            for (let i = 0; i < 10; i++) data[i] = {}, t[i] = 0;
            for (let i = 0; i < 10; i++) data[i] = JSON.parse(JSON.stringify(t));

            json.forEach((item, index) => {
                data[0][item.one] += 1;
                data[1][item.two] += 1;
                data[2][item.three] += 1;
                data[3][item.four] += 1;
                data[4][item.five] += 1;
            })
            let sortArr = [];
            for (let i = 0; i < 5; i++) {
                let d = data[i];
                let arr = [];
                for (let j = 0; j < 10; j++) arr.push({ [j]: d[j] });
                arr.sort((item1, item2) => {
                    return item2[Object.keys(item2)[0]] - item1[Object.keys(item1)[0]]
                })
                sortArr.push(arr);
            }
            return sortArr;
        }

        // testSortMinAndMax()
        async function testSortMinAndMax(num = 80) {
            let data = await new Promise((resolve, reject) => {
                fetch('http://106.13.233.100:3002/getLimitData/' + num, {}).then(response => {
                    if (response.status >= 200 && response.status < 300) { // 判断请求是否成功
                        return response.json() // 得到 JSON 对象
                    } else {
                        throw new Error(response.statusText);
                    }
                }).then(json => {
                    json = json.reverse()
                    sortArr = sortMinAndMax(json);
                    resolve(sortArr)
                }).catch(err => {
                    console.log('Request Failed', err)
                    reject(false)
                });
            })
            console.log('', data)
            return data;
        }

        fetch('http://106.13.233.100:3002/getLimitData/1200', {}).then(response => {
            if (response.status >= 200 && response.status < 300) { // 判断请求是否成功
                return response.json() // 得到 JSON 对象
            } else {
                throw new Error(response.statusText);
            }
        }).then(json => {
            json = json.reverse()
            let money = 100;
            let bs = [1, 3, 5, 5, 22, 44], nn = 0;
            for (let index = 20, start = 0; index < json.length; index++, start++) {
                const item = json[index];
                let arr = sortMinAndMax(json.slice(start, index));
                // console.log('', arr)
                let five = [];
                for (let i = 0; i < 5; i++) five.push(Number(Object.keys(arr[4][i])[0]));
                console.log('', five)
                console.log(`当期为${item.issueNo}号码为${[item.one, item.two, item.three, item.four, item.five]},预测下期${item.issueNo + 1}  ==== `)
                if (five.includes(item.five)) {
                    money = money + (4.8 * bs[nn])
                    nn = 0
                }
                else {
                    money = money - (5 * bs[nn])
                    nn++
                    if (nn > 5) nn = 0
                }
                console.log('', money)
            }

        }).catch(err => {
            console.log('Request Failed', err)
            reject(false)
        });



        // fetch('http://106.13.233.100:3002/getLimitData/2', {}).then(response => {
        //     if (response.status >= 200 && response.status < 300) { // 判断请求是否成功
        //         return response.json() // 得到 JSON 对象
        //     } else {
        //         throw new Error(response.statusText);
        //     }
        // }).then(json => {
        //     json = json.reverse()
        //     console.log('', json)

        //     let includes = [[], [], [], [], [],]
        //     let exclude = [[], [], [], [], [],]
        //     json.forEach((item) => {
        //         let data = [item.one, item.two, item.three, item.four, item.five]

        //         // 用上期时时彩开奖号码的万位与千位之间的正差值作为毒胆。(3期)
        //         let dd1 = Math.abs(data[0] - data[1]);
        //         inset(includes, dd1)

        //         // 用上期时时彩开奖号码的百位+十位十个位的和值尾数作为毒胆。(3期)
        //         let dd2 = data[2] + data[3] + data[4];
        //         if (dd2 > 9) inset(includes, dd2 % 10)
        //         else inset(includes, dd2);

        //         // 用上期时时彩开奖号码的十位号码所对应的一个数字作为毒胆。(3期)
        //         // [0, 8, 6, 4, 7, 9, 1, 2, 4, 6].forEach((i, ii) => {
        //         //     if (ii == data[3]) inset(includes, i)
        //         //     // console.log('i', i)
        //         // });

        //         // 用上期时时彩开奖号码的个位号码所对应的一个数字作为毒胆。(3期)
        //         // [1, 5, 3, 0, 7, 8, 2, 4, 3, 6].forEach((i, ii) => {
        //         //     if (ii == data[4]) inset(includes, i)
        //         // });

        //         // 用上期时时彩开奖号码的三星号码和值与跨度相加之和,取尾数作为毒胆。
        //         // console.log('kd(data)', kd(data))
        //         let dd3 = data[2] + data[3] + data[4] + kd(data);
        //         if (dd3 > 9) inset(includes, dd3 % 10)
        //         else inset(includes, dd3);

        //         console.log(`当期为${item.issueNo}号码为${data},预测下期${item.issueNo + 1}  ====  includes`, delRemoval(includes))
        //         console.log('', delRemoval(includes)[0])
        //         // console.log(`当期为${item.issueNo},预测下期${item.issueNo + 1}  ￥￥  exclude`, exclude)
        //         includes = [[], [], [], [], [],]
        //         exclude = [[], [], [], [], [],]
        //     })

        // }).catch(err => {
        //     console.log('Request Failed', err)
        // });

        function inset(obj, num) {
            obj.forEach((item, index) => {
                item.push(num);
            })
        }

        // 求跨度之差。obj.length > 1
        function kd(obj) {
            obj = JSON.parse(JSON.stringify(obj));
            let sort = obj.sort();
            return Math.abs(sort[0] - sort[sort.length - 1])
        }

        // 数组去重
        function delRemoval(arr) {
            arr.forEach((item) => {
                delRemoval_(item)
            })
            return arr
        }
    </script>
</body>

</html>